using System.Reflection;
using CustomORM.Mapping;
using NUnit.Framework;

namespace CustomORM.Tests.CustomORM.Mapping
{
    [TestFixture]
    public class MagicMapperTests
    {
        [Test]
        public void Constructor_ReflectsAssembly_EnsureThereAreMappersRegistered()
        {
            //MagicMapper.AddMapper(typeof(ClassJustAddedToMapper), new ClassJustAddedToMapperMap());
            var classJustAddedToMapperMap = new ClassJustAddedToMapperMap();
            // As we know there is mapper for ClassJustAddedToMapper, also on first call to MagicMapper mappers should be registered
            var recordData = MagicMapper.GetRecordData(new ClassJustAddedToMapper());
            //if we did not get exeptios we are fine, but we would also see if it at least works somehow
            Assert.That(recordData.FieldNames.Length, Is.GreaterThan(0));
            MagicMapper.RemoveMapper(typeof(ClassJustAddedToMapper));
        }

        internal class ClassJustAddedToMapper
        {
            public string SomeProperty { get; set; }
        }

        internal class ClassJustAddedToMapperMap: EntityToTableMapper<ClassJustAddedToMapper>
        {
            public ClassJustAddedToMapperMap()
            {
                Table("some_table_in_database");
                Id(x=>x.SomeProperty,"some_property_field");
            }
        }
    }
}
